# -*- coding: utf-8 -*-
from a115.utils.listutils import partial
from a115.utils.mathutils import dcml
from operator import concat

__all__ = ["str_until", "str_after", "chunk", "split_num", "phonetize", "phonetize_my_way"]

str_until = lambda c, s: s.partition(c)[0]
str_after = lambda c, s: s.partition(c)[2]
chunk = lambda s,n: [s[i:i+n] for i in range(0,len(s),n)]
camelCase = lambda s: s[0].lower() + s[1:]

_split_num = lambda n: _split_num(n[:-3]) + " " + n[-3:]  if len(n) else ''
def split_num(n):
    n = str(dcml(n))
    n, r = n.split(".") if n.find(".") >= 0 else (n, "00",)
    return _split_num(n).lstrip()+"."+r

M1_ = ((u"а,б,в,г,д,е,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ъ,ь,ю,я", "a,b,v,g,d,e,j,z,i,i,k,l,m,n,o,p,r,s,t,u,f,h,c,ch,sh,sht,y,i,iu,ia"))
M1 = dict(zip((M1_[0] + "," + M1_[0].upper()).split(","), (M1_[1] + "," + M1_[1].upper()).split(",")))
M2_ = ((u"а,б,в,г,д,е,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ъ,ь,ю,я", "a,b,w,g,d,e,v,z,i,j,k,l,m,n,o,p,r,s,t,u,f,h,c,`,[,],y,x,\\,q"))
M2 = dict(zip((M2_[0] + "," + M2_[0].upper()).split(","), (M2_[1] + "," + M2_[1].upper()).split(",")))
phonetize = lambda s, M=M1: reduce(concat, map(lambda c: M.get(c, c), s), '')
phonetize_my_way = partial(phonetize, M=M2)

